home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / src / allmain.c next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  9.5 KB  |  443 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)allmain.c    3.1    93/06/16    */
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /* various code that was replicated in *main.c */
  6.  
  7. #include "hack.h"
  8.  
  9. #ifndef NO_SIGNAL
  10. #include <signal.h>
  11. #endif
  12.  
  13. #ifdef OVL0
  14.  
  15. void
  16. moveloop()
  17. {
  18. #ifdef MICRO
  19.     char ch;
  20.     int abort_lev;
  21. #endif
  22.     int moverate = 0;
  23.     boolean didmove = 0;
  24.  
  25.     /* Note:  these initializers don't do anything except guarantee that
  26.         we're linked properly.
  27.     */
  28.     decl_init();
  29.     monst_init();
  30.     monstr_init();    /* monster strengths */
  31.     objects_init();
  32.  
  33.     (void) encumber_msg(); /* in case they auto-picked up something */
  34.  
  35.     for(;;) {
  36. #ifdef CLIPPING
  37.         cliparound(u.ux, u.uy);
  38. #endif
  39. #if defined(MAC_MPW32) && !defined(MODEL_FAR)
  40.         UnloadAllSegments();  /* Marks non-resident segments as purgeable */
  41. #endif
  42.         get_nh_event();
  43.  
  44.         didmove = flags.move;
  45.         if(flags.move) {    /* actual time passed */
  46. #ifdef POLYSELF
  47.             int oldmtimedone;
  48. #endif
  49.             int wtcap;
  50.  
  51.             if (u.utotype) deferred_goto();
  52.             wtcap = encumber_msg();
  53. #ifdef POLYSELF
  54.             oldmtimedone = u.mtimedone;
  55. #endif
  56.  
  57. #ifdef SOUNDS
  58.             dosounds();
  59. #endif
  60.  
  61.             if(moverate <= 0) {
  62.             /* calculate how much time passed. */
  63.             int moveamt = 0;
  64.             if(Fast & ~INTRINSIC) moveamt = 6;
  65.             else if(Fast) moveamt = 8;
  66.             else moveamt = 12;
  67.  
  68.             switch(wtcap) {
  69.             case UNENCUMBERED: break;
  70.             case SLT_ENCUMBER: moveamt = (moveamt * 4) / 3; break;
  71.             case MOD_ENCUMBER: moveamt *= 2; break;
  72.             case HVY_ENCUMBER: moveamt *= 4; break;
  73.             default: moveamt *= 12; break;
  74.             }
  75.             moverate += moveamt;
  76.             settrack();
  77.             }
  78.  
  79.             if(moverate > 0) {
  80.             movemon();
  81.             /* a monster may have levteleported player -dlc */
  82.             if (u.utotype) deferred_goto();
  83.             if(!rn2(u.uevent.udemigod ? 25 :
  84.                 (depth(&u.uz) >
  85.                  depth(&stronghold_level))
  86.                 ? 50 : 70))
  87.                 (void) makemon((struct permonst *)0, 0, 0);
  88.             ++monstermoves;
  89.             remove_cadavers(&fobj);
  90.             remove_cadavers(&invent);
  91.             moverate -= 12;
  92.             }
  93.             if(Glib) glibr();
  94.             nh_timeout();
  95.             ++moves;
  96.             if (u.ublesscnt)  u.ublesscnt--;
  97.             if(flags.time) flags.botl = 1;
  98.             /* One possible result of prayer is healing.  Whether or
  99.              * not you get healed depends on your current hit points.
  100.              * If you are allowed to regenerate during the prayer, the
  101.              * end-of-prayer calculation messes up on this.
  102.              */
  103.             if (u.uinvulnerable)
  104.             ;
  105.             else
  106. #ifdef POLYSELF
  107.             if (u.mtimedone && u.mh < u.mhmax) {
  108.             if (u.mh < 1) {
  109.                 rehumanize();
  110.                 moverate = 0;
  111.             } else if (Regeneration ||
  112.                  (wtcap < MOD_ENCUMBER && !(moves%20))) {
  113.                 flags.botl = 1;
  114.                 u.mh++;
  115.             }
  116.             } else
  117. #endif
  118.             if(u.uhp < u.uhpmax) {
  119.             if(u.ulevel > 9) {
  120.                 int heal;
  121.  
  122.                 if(HRegeneration ||
  123.                    (!(moves%3) &&
  124.                 (wtcap < MOD_ENCUMBER || !flags.mv))) {
  125.                 flags.botl = 1;
  126.                 if (ACURR(A_CON) <= 12) heal = 1;
  127.                 else heal = rnd((int) ACURR(A_CON)-12);
  128.                 if (heal > u.ulevel-9) heal = u.ulevel-9;
  129.                 u.uhp += heal;
  130.                 if(u.uhp > u.uhpmax)
  131.                     u.uhp = u.uhpmax;
  132.                 }
  133.             } else if(HRegeneration ||
  134.                   ((wtcap < MOD_ENCUMBER || !flags.mv) &&
  135.                    (!(moves%((MAXULEV+12)/(u.ulevel+2)+1))))) {
  136.                 flags.botl = 1;
  137.                 u.uhp++;
  138.             }
  139.             }
  140.  
  141.             if (wtcap > MOD_ENCUMBER && flags.mv) {
  142.             if(!(wtcap < EXT_ENCUMBER ? moves%30 : moves%10)) {
  143.                 if(u.uhp > 1) {
  144.                 u.uhp--;
  145.                 } else {
  146.                 pline("You pass out from exertion!");
  147.                 exercise(A_CON, FALSE);
  148.                 nomul(-10);
  149.                 u.usleep = 1;
  150.                 }
  151.             }
  152.             }
  153.  
  154.             if ((u.uen < u.uenmax) &&
  155.             ((wtcap < MOD_ENCUMBER &&
  156.               (!(moves%((MAXULEV + 1 - u.ulevel) *
  157.                     (pl_character[0] == 'W' ? 3 : 4) / 2))))
  158.              || Energy_regeneration)) {
  159.             u.uen +=
  160.                 rn1((int)(ACURR(A_WIS) + ACURR(A_INT)) / 10 + 1,1);
  161.             if (u.uen > u.uenmax)  u.uen = u.uenmax;
  162.             flags.botl = 1;
  163.             }
  164.  
  165.             if(!u.uinvulnerable) {
  166.             if(Teleportation && !rn2(85)) {
  167. #ifdef REDO            /* clear doagain keystrokes */
  168.                 pushch(0);
  169.                 savech(0);
  170. #endif
  171.                 tele();
  172.             }
  173. #ifdef POLYSELF
  174.             if(Polymorph && !rn2(100)) {
  175.                 if (multi >= 0) {
  176.                 if (occupation)
  177.                     stop_occupation();
  178.                 else
  179.                     nomul(0);
  180.                 }
  181.                 polyself();
  182.                 moverate = 0;
  183.             } else if (u.ulycn >= 0 && !rn2(80 - (20 * night()))) {
  184.                 if (multi >= 0) {
  185.                 if (occupation)
  186.                     stop_occupation();
  187.                 else
  188.                     nomul(0);
  189.                 }
  190.                 you_were();
  191.                 moverate = 0;
  192.             }
  193. #endif
  194.             }
  195.  
  196.             if(Searching && multi >= 0) (void) dosearch0(1);
  197.             do_storms();
  198.             hatch_eggs();
  199.             burn_lamps();
  200.             gethungry();
  201.             exerchk();
  202.             invault();
  203.             amulet();
  204.             if (!rn2(40+(int)(ACURR(A_DEX)*3))) 
  205.             u_wipe_engr(rnd(3));
  206.             if (u.uevent.udemigod && !u.uinvulnerable) {
  207.             if (u.udg_cnt) u.udg_cnt--;
  208.             if (!u.udg_cnt) {
  209.                 intervene();
  210.                 u.udg_cnt = rn1(200, 50);
  211.             }
  212.             }
  213.             restore_attrib();
  214.             /* underwater and waterlevel vision are done here */
  215.             if (Is_waterlevel(&u.uz))
  216.             movebubbles();
  217.             else if (Underwater)
  218.             under_water(0);
  219.  
  220. #ifdef POLYSELF
  221.             if ((oldmtimedone && !u.mtimedone) ||
  222.             (!oldmtimedone && u.mtimedone)) moverate = 0;
  223. #endif
  224.         }
  225.         if(multi < 0) {
  226.             if(!++multi){
  227.                 pline(nomovemsg ? nomovemsg :
  228.                     (const char *)"You can move again.");
  229.                 nomovemsg = 0;
  230.                 u.usleep = 0;
  231.                 if(afternmv) (*afternmv)();
  232.                 afternmv = 0;
  233.             }
  234.         }
  235.  
  236.         find_ac();
  237.         if(!flags.mv || Blind) {
  238.             /* redo monsters if hallu or wearing a helm of telepathy */
  239.             if (Hallucination ||
  240.             (HTelepat & (WORN_HELMET|WORN_AMUL|W_ART)))
  241.             see_monsters();
  242.  
  243.             /* redo objects if hallucinating */
  244.             if (Hallucination) see_objects();
  245.  
  246.             /* update swallowed display */
  247.             if (Hallucination && u.uswallow) swallowed(0);
  248.  
  249.             if (vision_full_recalc) vision_recalc(0);    /* vision! */
  250.         }
  251.         if(flags.botl || flags.botlx) bot();
  252.  
  253.         flags.move = 1;
  254.  
  255.         if(multi >= 0 && occupation) {
  256. #ifdef MICRO
  257.             abort_lev = 0;
  258.             if (kbhit()) {
  259.                 if ((ch = Getchar()) == ABORT)
  260.                     abort_lev++;
  261. # ifdef REDO
  262.                 else
  263.                     pushch(ch);
  264. # endif /* REDO */
  265.             }
  266.             if (!abort_lev && (*occupation)() == 0)
  267. #else
  268.             if ((*occupation)() == 0)
  269. #endif
  270.                 occupation = 0;
  271.             if(
  272. #ifdef MICRO
  273.                abort_lev ||
  274. #endif
  275.                monster_nearby()) {
  276.                 stop_occupation();
  277.                 reset_eat();
  278.             }
  279. #ifdef MICRO
  280.             if (!(++occtime % 7))
  281.                 display_nhwindow(WIN_MAP, FALSE);
  282. #endif
  283.             continue;
  284.         }
  285.  
  286.         if((u.uhave.amulet || Clairvoyant) && !In_endgame(&u.uz) &&
  287.                         !(moves%15) && !rn2(2))
  288.             do_vicinity_map();
  289.  
  290.         if(u.utrap && u.utraptype == TT_LAVA) {
  291.             if(!is_lava(u.ux,u.uy))
  292.             u.utrap = 0;
  293.             else {
  294.             u.utrap -= 1<<8;
  295.             if(u.utrap < 1<<8) {
  296.                 killer_format = KILLED_BY;
  297.                 killer = "molten lava";
  298.                 You("sink below the surface and suffocate.");
  299.                 done(DROWNING); /*whatever*/
  300.             } else if(didmove && !u.umoved) {
  301.                 Norep("You sink deeper into the lava.");
  302.                 u.utrap += rnd(4);
  303.             }
  304.             }
  305.         }
  306.  
  307.         u.umoved = FALSE;
  308.         if(!didmove || moverate <= 0) {
  309.             if(multi > 0) {
  310.             lookaround();
  311.             if(!multi) {    /* lookaround may clear multi */
  312.                 flags.move = 0;
  313.                 continue;
  314.             }
  315.             if(flags.mv) {
  316.                 if(multi < COLNO && !--multi)
  317.                     flags.mv = flags.run = 0;
  318.                 domove();
  319.             } else {
  320.                 --multi;
  321.                 rhack(save_cm);
  322.             }
  323.             } else if(multi == 0) {
  324. #ifdef MAIL
  325.             ckmailstatus();
  326. #endif
  327.             rhack(NULL);
  328.             }
  329.         }
  330.         if (vision_full_recalc) vision_recalc(0);    /* vision! */
  331.         if(multi && multi%7 == 0)
  332.             display_nhwindow(WIN_MAP, FALSE);
  333.     }
  334. }
  335.  
  336. #endif /* OVL0 */
  337. #ifdef OVL1
  338.  
  339. void
  340. stop_occupation()
  341. {
  342.     if(occupation) {
  343.         You("stop %s.", occtxt);
  344.         occupation = 0;
  345. /* fainting stops your occupation, there's no reason to sync.
  346.         sync_hunger();
  347. */
  348. #ifdef REDO
  349.         nomul(0);
  350.         pushch(0);
  351. #endif
  352.     }
  353. }
  354.  
  355. #endif /* OVL1 */
  356. #ifdef OVLB
  357.  
  358. void
  359. display_gamewindows()
  360. {
  361.     WIN_MESSAGE = create_nhwindow(NHW_MESSAGE);
  362.     WIN_STATUS = create_nhwindow(NHW_STATUS);
  363.     WIN_MAP = create_nhwindow(NHW_MAP);
  364.     WIN_INVEN = create_nhwindow(NHW_MENU);
  365.  
  366. #ifdef MAC
  367.     /*
  368.      * This _is_ the right place for this - maybe we will
  369.      * have to split display_gamewindows into create_gamewindows
  370.      * and show_gamewindows to get rid of this ifdef...
  371.      */
  372.     if ( ! strcmp ( windowprocs . name , "mac" ) ) {
  373.         SanePositions ( ) ;
  374.     }
  375. #endif
  376.  
  377.     /*
  378.      * The mac port is not DEPENDENT on the order of these
  379.      * displays, but it looks a lot better this way...
  380.      */
  381.     display_nhwindow(WIN_STATUS, FALSE);
  382.     display_nhwindow(WIN_MESSAGE, FALSE);
  383.     clear_glyph_buffer();
  384.     display_nhwindow(WIN_MAP, FALSE);
  385. }
  386.  
  387. void
  388. newgame()
  389. {
  390. #ifdef MFLOPPY
  391.     gameDiskPrompt();
  392. #endif
  393.  
  394.     fobj = invent = level.buriedobjlist = migrating_objs = (struct obj *)0;
  395.     fmon = migrating_mons = (struct monst *)0;
  396.     ftrap = 0;
  397.     flags.ident = 1;
  398.  
  399.     if(wiz1_level.dlevel == 0) init_dungeons();
  400.     init_objects();        /* must be before u_init() */
  401.     u_init();
  402.     init_artifacts();    /* must be after u_init() */
  403.  
  404. #ifndef NO_SIGNAL
  405.     (void) signal(SIGINT, (SIG_RET_TYPE) done1);
  406. #endif
  407. #ifdef NEWS
  408.     if(flags.news) display_file(NEWS, FALSE);
  409. #endif
  410. #ifdef MULDGN
  411.     load_qtlist();    /* load up the quest text info */
  412.     quest_init();
  413.     if(flags.legacy && moves == 1) com_pager(1);
  414. #endif
  415.     mklev();
  416.     u_on_upstairs();
  417.     check_special_room(FALSE);
  418.     vision_reset();        /* set up internals for level (after mklev) */
  419.  
  420.     flags.botlx = 1;
  421.  
  422.     /* Move the monster from under you or else
  423.      * makedog() will fail when it calls makemon().
  424.      *             - ucsfcgl!kneller
  425.      */
  426.     if(MON_AT(u.ux, u.uy)) mnexto(m_at(u.ux, u.uy));
  427.  
  428. #ifdef CLIPPING
  429.     cliparound(u.ux, u.uy);
  430. #endif
  431.     (void) makedog();
  432.     docrt();
  433.  
  434. #ifdef INSURANCE
  435.     save_currentstate();
  436. #endif
  437.     return;
  438. }
  439.  
  440. #endif /* OVLB */
  441.  
  442. /*allmain.c*/
  443.